package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.ICompanyDao;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.util.JDBCUtils;

import java.sql.ResultSet;
import java.sql.SQLException;

public class CompanyDaoImpl implements ICompanyDao {
    @Override
    public CompanyModel getCompany() {
        String sql = "select * from company";
        ResultSet rs =  JDBCUtils.getResultSet(sql);
        CompanyModel company = null;
        try {
            if (rs.next()){
                company = new CompanyModel();
                company.setAd(rs.getString("ad"));
                company.setAddress(rs.getString("address"));
                company.setCopyright(rs.getString("copyright"));
                company.setCpy_intro(rs.getString("cpy_intro"));
                company.setEmail(rs.getString("email"));
                company.setEnglish_name(rs.getString("english_name"));
                company.setFax(rs.getString("fax"));
                company.setIntro(rs.getString("intro"));
                company.setLogo(rs.getString("logo"));
                company.setName(rs.getString("name"));
                company.setPhone(rs.getString("phone"));
                company.setWebsite(rs.getString("website"));
                company.setWork_time(rs.getString("work_time"));
            }
            rs.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return company;
    }

    @Override
    public int editCompany(CompanyModel company) {
        String sql = "update company set ad='"+company.getAd()
                +"',address='"+company.getAddress()
                +"',copyright='"+company.getCopyright()
                +"',cpy_intro='"+company.getCpy_intro()
                +"',email='"+company.getEmail()
                +"',english_name='"+company.getEnglish_name()
                +"',fax='"+company.getFax()
                +"',intro='"+company.getIntro()
                +"',logo='"+company.getLogo()
                +"',name='"+company.getName()
                +"',phone='"+company.getPhone()
                +"',website='"+company.getWebsite()
                +"',work_time='"+company.getWork_time()
                +"',update_time='"+company.getUpdateTime()+"'";
        return JDBCUtils.excute(sql);
    }
}
